package com.example.testproject.adapter

import android.view.LayoutInflater
import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.example.testproject.R
import com.example.testproject.bean.TopicDetailsBean
import com.example.testproject.bean.TopicSecondBean
import com.example.testproject.utils.SwitchDialogFragment
import com.example.testproject.utils.toast
import kotlinx.android.synthetic.main.topic_details_item.view.*

/**
 *
 * @ClassName: TopicSubmitAdapter
 * @Author: android 超级兵
 * @CreateDate: 10/28/21$ 11:16 AM$
 * TODO
 */
class TopicSubmitAdapter(data: ArrayList<TopicDetailsBean>) :
    BaseQuickAdapter<TopicDetailsBean, BaseViewHolder>(R.layout.topic_details_item, data) {
    override fun convert(helper: BaseViewHolder, item: TopicDetailsBean) {
        helper.setText(R.id.tvType, typeJudge(item.type))

        helper.itemView.topicDetailsRv.layoutManager = GridLayoutManager(mContext, 4)

        val topicDetailsAdapter = TopicDetailsAdapter(item.child)

        helper.itemView.topicDetailsRv.adapter = topicDetailsAdapter

        topicDetailsAdapter.setOnItemClickListener { _, _, position ->
            click.clickCallBack(item.type,topicDetailsAdapter.data[position])
        }
    }

    /*
     * 作者:android 超级兵
     * 创建时间: 10/28/21 1:35 PM
     * TODO 根据type判断类型
     */
    fun typeJudge(type: Int) = let {
        when (type) {
            TopicAdapter.SINGLE_CHOICE -> {
                "单选题"
            }
            TopicAdapter.MULTIPLE_CHOICE -> {
                "多选题"
            }
            TopicAdapter.JUDGE -> {
                "判断题"
            }
            TopicAdapter.FILL -> {
                "填空题"
            }
            else -> "暂无类型"
        }
    }

    interface OnTopicSubmitListener {
        // 类型
        // dialog输出的数据
        fun clickCallBack(type: Int,topicSecondBean: TopicSecondBean)
    }

    lateinit var click: OnTopicSubmitListener


}